<?php

namespace api\modules\v1\controllers;
use api\common\controllers\CommonController;
use api\modules\v1\models\News;
use yii\web\HttpException;
use yii\web\NotFoundHttpException;
use yii\helpers\ArrayHelper;
use Yii;

class NewsController extends CommonController
{
    public $modelClass = 'api\modules\v1\models\News';

    public function actions()
    {
        return [
            'index' => [
                'class' => 'yii\rest\IndexAction',
                'modelClass' => $this->modelClass,
                'prepareDataProvider' => [$this, 'prepareDataProvider']
            ],
            'options' => [
                'class' => 'yii\rest\OptionsAction'
            ]
        ];
    }

    /*
     * 列表显示
     * @return ActiveDataProvider
     */
    public function prepareDataProvider()
    {
        $modelClass = $this->modelClass;
        $searchModel = new $modelClass();
        $dataProvider = $searchModel->search(\Yii::$app->request->queryParams);
        return $dataProvider;
    }

    /*
     * 获取文章详情
     * @param $id
     */
    public function actionInfo($id,$catid){
        $modelClass = $this->modelClass;
        $Model = new $modelClass();
        $Model->PushTj($id,$catid);
        return $Model->getInfo();
    }

}